package net.ryian.sms;

import net.ryian.sms.service.ISmsService;
import net.ryian.sms.service.impl.DayuSmsService;
import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * 短信服务调用入口，通过sms.properties里的配置，使用相应的短信网关及配置
 * 
 * @author wangcheng
 *
 */
public class SmsService {

	private static final Logger logger = Logger.getLogger(SmsService.class);
	public static SmsService INSTANCE = new SmsService();
	public ISmsService service;

	private SmsService() {
		Properties prop = new Properties();

		try {
			prop.load(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream("sms.properties"), "UTF-8"));
		} catch (IOException var5) {
			logger.error(var5);
		}

		String serviceProvider = prop.getProperty("service_provider");

		try {
			this.service = (ISmsService)Class.forName(serviceProvider).newInstance();
		} catch (Exception var4) {
			logger.error(var4);
		}

	}

	public void sendSms(String mobile, String msg) throws Exception {
		this.service.send(mobile, msg);
	}

	public void sendSms(String mobile, String template, String... values) throws Exception {
		this.service.send(mobile, template, values);
	}
	public void flexibleSendSms(String mobile, String templatecode, String signature,String... values) throws Exception {
		this.service.send(mobile, templatecode, signature, values);
	}

	public static void main(String[] s) {
		try {
			INSTANCE.flexibleSendSms("18523290543", "SMS_134320424", "海e行智慧版","111111");
		} catch (Exception var2) {
			logger.error(var2);
		}

	}

}
